<template>
	<!-- 封装的多行输入框 -->
	<div class="ftextarea">
		<textarea @input="change" class="centbox" v-model="newvalue" :maxlength="maxlength" :placeholder="placeholder"
			:disabled="disabled" />
	</div>
</template>

<script>
	// 引入正则的js
	export default {
		name: 'ftextarea', //封装的多行输入框
		props: {
			// 输入框初始内容
			value: {
				type: [String, Number],
			},
			// 是否禁用
			disabled: {
				type: [Boolean],
				default: false
			},
			//最大输入长度
			maxlength: {
				type: [Number],
				default: -1
			},
			// 输入框默认输入内容
			placeholder: {
				type: [String],
				default: '请输入'
			},
		},
		data() {
			return {
				newvalue: "", //输入框内容
			}
		},
		watch: {
			// 初始化同步数据 
			value: {
				handler(newName, oldName) {
					this.newvalue = newName || '';
				},
				deep: true,
				immediate: true
			}
		},
		methods: {
			// 数据变化时触发
			change() {
				// 停止输入后触发(.5s后停止)。
				this.way.debounce(500).then(() => {
					this.$emit('update:value', this.newvalue)
					this.$emit("change", this.newvalue)
				});
			},

		}
	}
</script>

<style lang="less" scoped>
	// 封装的多行输入框
	.ftextarea {
		position: relative;
		padding: 18rpx 24rpx;
		border: 1px solid #E7EBF5;
		border-radius: 20rpx;
		min-height: 160rpx;
		font-size: 28rpx;

		.centbox {
			width: 100%;
			height: 100%;
			height: 160rpx;
		}
	}
</style>